import {
  superExamineTodoMeAPI
} from '@/api/oa/superExamine'

import { isEmpty } from '@/utils/types'
/**
 * 审批代办消息
 */
const app = {
  state: {
    // 审批代办消息
    backlogNum: ''

  },

  mutations: {
    /**
     * 更改待办事项
     */
    SET_BACKLOGNUM: (state, messageNum) => {
      state.backlogNum = messageNum
    }

  },

  actions: {
    // 登录
    GetBacklogNum({
      getters
    }) {
      return new Promise((resolve, reject) => {
        const params = {
          page: 1,
          limit: 1
        }
        superExamineTodoMeAPI(params)
          .then(response => {
            const item = getters.oaRouters.find(item => item.path === '/oa/examine')
            if (!isEmpty(item)) {
              item.children.forEach(element => {
                if (element.path === 'subs/statistics/upcoming') {
                  element.meta.num = response.data.totalRow || ''
                }
              })
            }
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    }

  }
}

export default app
